/**
 * jims
 */
package com.jims.master.modules.med.web;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.common.web.BaseController;
import com.jims.master.modules.med.entity.MedicalCardRechangeRec;
import com.jims.master.modules.med.service.MedicalCardRechangeRecService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 充值Controller
 * @author 陈晓阳
 * @version 2017-05-22
 */
@Controller
@RequestMapping(value = "${adminPath}/med/medicalCardRechangeRec")
public class MedicalCardRechangeRecController extends BaseController {

	@Autowired
	private MedicalCardRechangeRecService medicalCardRechangeRecService;
	
	@ModelAttribute
	public MedicalCardRechangeRec get(@RequestParam(required=false) String id) {
		MedicalCardRechangeRec entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = medicalCardRechangeRecService.get(id);
		}
		if (entity == null){
			entity = new MedicalCardRechangeRec();
		}
		return entity;
	}

    /**
     * 充值统计
     * @param medicalCardRechangeRec
     * @param request
     * @param response
     * @param model
     * @return
     */
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(MedicalCardRechangeRec medicalCardRechangeRec, HttpServletRequest request, HttpServletResponse response, Model model) {
        medicalCardRechangeRec.setRechangeFlag("0");
        Page<MedicalCardRechangeRec> page = medicalCardRechangeRecService.findPage(new Page<MedicalCardRechangeRec>(request, response), medicalCardRechangeRec);
        model.addAttribute("page", page);
        model.addAttribute("medicalCardRechangeRec", medicalCardRechangeRec);
        return "modules/med/medicalCardRechangeRecIndex";
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(MedicalCardRechangeRec medicalCardRechangeRec, Model model) {
		model.addAttribute("medicalCardRechangeRec", medicalCardRechangeRec);
		return "modules/med/medicalCardRechangeRecForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(MedicalCardRechangeRec medicalCardRechangeRec, Model model) {
	    StringData data=new StringData();
		int i=medicalCardRechangeRecService.save(medicalCardRechangeRec);
        if(i>0){
            data.setCode("success");
            data.setData("保存充值成功");
        }else{
            data.setCode("error");
            data.setData("保存充值失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(MedicalCardRechangeRec medicalCardRechangeRec) {
	    StringData data=new StringData();
		int i=medicalCardRechangeRecService.delete(medicalCardRechangeRec);
        if(i>0){
            data.setCode("success");
            data.setData("删除充值成功");
        }else{
            data.setCode("error");
            data.setData("删除充值失败");
        }
		return data;
	}

}